package org.sirmupadbapi.generales;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ResourceBundle;
/**
*
 * @author
*/
public class DataGManager implements Serializable {
private static final long serialVersionUID = 1L;
private static String username;
private static String password;
private static String url;
private static String driver;
private static String database;
private static String driverClassName;
private static String proyecto;
private static String resourcename;
private static String tipo;
private static String type;
public static Exception excepcion;
public static Connection con = null;
public DataGManager() {
 try {
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "DataGManager()");
  }
}

public boolean LoadConfiguration() {
 try {
  ResourceBundle rb = ResourceBundle.getBundle("org.sirmupadbapi.properties.configuration");
    excepcion = null;
    this.proyecto = rb.getString("proyecto");
    this.username = rb.getString("username");
    this.password = rb.getString("password");
    this.url = rb.getString("url");
    this.driver = rb.getString("driverClassName");
    this.database = rb.getString("database");
    this.driverClassName = rb.getString("driverClassName");
    this.resourcename = rb.getString("Resourcename");
    this.tipo = rb.getString("tipo");
    this.type = rb.getString("type");
    return true;
  } catch (Exception e) {
    Mensajeria.MensajeError(e, "Sesion.java CargarConfiguracion()");
  }
  return false;
}

/*
 WithOutTransaction()
*/

public boolean WithOutTransaction() {
 try {
     con.setAutoCommit(true);
     return true;
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "WithOutTransaction()");
  }
    return false;
 }

/*
 BeginTransaction()
*/

public boolean BeginTransaction() {
 try {
     con.setAutoCommit(false);
     return true;
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "BeginTransaction()");
  }
    return false;
 }

/*
 Commit()
*/

public boolean Commit() {
 try {
     con.commit();
     return true;
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "Commit()");
  }
    return false;
 }

/*
 Roolback()
*/

public boolean Roolback() {
 try {
     con.rollback();
     return true;
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "Roolback()");
  }
    return false;
 }

/*
 EndTransaction()
*/

public boolean EndTransaction() {
 try {
     con.setAutoCommit(true);
     return true;
    } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "EndTransaction()");
  }
    return false;
 }

/*
 OpenConnection()
*/

public Connection OpenConnection() {
 try {
     LoadConfiguration();
     Class.forName(driver).newInstance();
     con = DriverManager.getConnection(url, this.username, this.password);
     if (con == null) {
        return null;
      }
     return con;
  } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "OpenConnection()");
  }
    return null;
 }

/*
 Connect()
*/

public Connection Connect() {
 try {
    if (con == null) {
       return null;
    }
       return con;
  } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "Connect()");
  }
    return null;
 }

/*
 Connect()
*/

 public boolean CloseConnection() {
 try {
 
  if (con == null) {
  return true;
 }
 con.close();
 return true;
 } catch (Exception ex) {
     Mensajeria.MensajeError(ex, "CloseConnection()");
 }
 return false;
 }

/*
 getCon()
*/

 public static Connection getCon() {
    return con;
 }
} 
